package com.leet.code.lcof;


import java.util.Arrays;

public class Code56_1 {
    public static void main(String[] args) {
        int[] is = {4, 1, 4, 6};
        System.out.println(Arrays.toString(new Code56_1().singleNumbers(is)));

    }

    public int[] singleNumbers(int[] nums) {

        int r1 = 0;
        for (int i : nums) {
            r1 = r1 ^ i;
        }
        int i = 1;
        while ((r1 & i) != i) {
            i = i << 1;
        }

        int result1 = 0;
        int result2 = 0;
        for (int j : nums) {
            if ((j & i) == i) {
                result1 = result1 ^ j;
            } else {
                result2 = result2 ^ j;
            }
        }

        return new int[]{result1, result2};
    }
}
